<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/table.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/dwz/themes/default/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="${pageContext.request.contextPath}/dwz/themes/css/core.css" rel="stylesheet" type="text/css" media="screen" />
<script src="${pageContext.request.contextPath}/jquery/jquery-2.1.4.min.js" type="text/javascript"></script>
<table border="0" cellpadding="0" cellspacing="0" class="table_border">
    <tr>
        <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="0"
                   class="table_padding">
                <tr>
                    <td>
                        <table align="left">
                            <tr>
                                <td width="75px"><a class="button" id="datailBtn" href="javascript:void(0)"><span>查看明细</span></a>
                                </td>
                                <td width="50px"><a class="button" href="role?method=add"><span>新增</span></a>
                                </td>
                                <td width="50px"><a class="button" id = "delBtn" href="javascript:void(0);"><span>删除</span></a></td>
                                <td width="50px"><a class="button" href="role?mothod=edit"><span>修改</span></a>
                                </td>
                                <td width="80px"><a class="button" href="role?mothod=assign"><span>分配许可</span></a>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td width="25" height="26" align="right"></td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">
            <table border="0" cellpadding="0" cellspacing="0" id="box_num_table2"
                   class="box_num_table">
                <thead>
                <tr  bgcolor="white">
                    <td><input id="topSelect" type="checkbox" /></td>
                    <td>序号</td>
                    <td>代码</td>
                    <td>名称</td>
                    <td>描述</td>
                </tr>
                </thead>
                <tbody id="dataBody">
<%--                    <tr  bgcolor="white">--%>
<%--                        <td><input type="checkbox" /></td>--%>
<%--                        <td>1</td>--%>
<%--                        <td>001</td>--%>
<%--                        <td>管理员</td>--%>
<%--                        <td>&nbsp;</td>--%>
<%--                    </tr>--%>
<%--                    <tr  bgcolor="white">--%>
<%--                        <td><input type="checkbox" /></td>--%>
<%--                        <td>2</td>--%>
<%--                        <td>&nbsp;</td>--%>
<%--                        <td>&nbsp;</td>--%>
<%--                        <td>&nbsp;</td>--%>
<%--                    </tr>--%>
                </tbody>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <table border="0" cellpadding="0" cellspacing="0"
                   class="table_border">
                <tr>
                    <td>
                        <table width="100%" border="0" cellpadding="0" cellspacing="0"
                               class="table_padding">
                            <tr>
                                <td width="8%" class="font_left">数据:120条</td>
                                <td width="12" class="font_left">第</td>
                                <td width="375" class="font_left">
                                    <input name="textfield2" type="text" size="2" maxlength="4" /> /5页
                                </td>
                                <td width="478" class="font_right">
                                    <a href="">首页</a>
                                    <a href="">上一页</a>
                                    <a href="">下一页</a>
                                    <a href="">末页</a>
                                    <a href="">刷新</a>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>

        </td>
    </tr>
</table>
<script>
    $(function () {
        getByPage(1,3);
    });
    function getByPage(pageNo,pageSize){
        //向后台发送请求 加载页面
        $.get("role?method=getByPage&pageNo="+pageNo+"&pageSize="+pageSize,function (result) {
            var str;
            $.each(result,function (i,n) {//i 循环次数 n 返回结果中的对象
                str+='<tr  bgcolor="white">' +
                    '<td><input onclick="contorlTop()" type="checkbox" value="'+n.id+'"/></td>' +
                    '<td>'+(i+1)+'</td>' +
                    '<td>'+n.code+'</td>' +
                    '<td>'+n.name+'</td>' +
                    '<td>'+n.remark+'</td>' +
                    '</tr>';
            });
            $("#dataBody").html(str);
        });
    }




    $("#datailBtn").click(function () {
        var boxLength = $(":checkbox:checked").length;

        if (boxLength!=1){
            alert("只能选择一条数据进行查看");
            return;
        }
        //向后台发送请求
        location.href = "role?method=detail&id="+$(":checkbox:checked").val();
    });


    $("#topSelect").click(function () {
        //全选 全不选
        $(":checkbox:checkbox[id!=topSelect]").prop("checked",this.checked)
    });
    //通过其他的复选框确认第一个复选框的状态
    function contorlTop(){
        //除了第一个复选框的数量
        var boxOtherLength = $(":checkbox[id!='topSelect']").length;
        //除了第一个复选框，其余选中的复选框数量
        var boxSelect = $(":checkbox:checked[id!='topSelect']").length;
        $("#topSelect").prop("checked",boxOtherLength==boxSelect);
    }




    $("#delBtn").click(function (){
        var boxLength = $(":checkbox:checked").length;

        if (boxLength<1){
            alert("至少选择一条数据进行删除");
            return;
        }
        var ids="";
        $(":checkbox:checked[id!='topSelect']").each(function (i,n) {
            ids+=n.value+"-";
        });
        $.get("role?method=del&ids="+ids,function (result) {
            if (result.code=="200"){
                getByPage(1,3);
                alert("删除成功");
            }
        })
    });
</script>
